/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package explorer;

import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Carmen
 */
public class FileTableModel extends AbstractTableModel {

    private ArrayList<FileModel> _fileList = new ArrayList<FileModel>();
    private String _headers[] = {"Nom", "Taille", "Lecture", "Ecriture", "_Répertoire", "Date de dernière modification"};
    private boolean _showHidden = false;
    
    public FileTableModel() {
        super();
    }

    public FileTableModel(ArrayList<FileModel> fileList) {
        this(fileList, false);
    }
    
    public FileTableModel(ArrayList<FileModel> fileList, boolean hidden) {
        this();
        _showHidden = hidden;
        if (hidden) {
            _fileList = fileList;
        } else {
            for (FileModel fm : fileList) {
                if (!fm.isHidden()) {
                    _fileList.add(fm);
                }
            }
        }
        
    }

    /**
     * @return the _fileList
     */
    public ArrayList<FileModel> getFileList() {
        return _fileList;
    }

    /**
     * @param fileList the _fileList to set
     */
    public void setFileList(ArrayList<FileModel> fileList) {
        this._fileList = fileList;
    }

    @Override
    public int getRowCount() {
        return getFileList().size();
    }

    @Override
    public int getColumnCount() {
        return _headers.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return _headers[columnIndex];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        FileModel fm = _fileList.get(rowIndex);

        switch (columnIndex) {
            case 0:
                return fm.getName();

            case 1:
                return fm.getSize();

            case 2:
                return fm.isReadable();

            case 3:
                return fm.isWritable();
            
            case 4:
                return fm.isDirectory();
                
            case 5:
                return fm.getLastModified();

                
            default:
                return null;
        }
    }
    
    
    
    @Override
    public Class getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;
            case 1:
                return Long.class;
            case 2:
                return Boolean.class;
            case 3:
                return Boolean.class;
            case 4:
                return Boolean.class;
            case 5:
                return Date.class;
            default:
                return Object.class;
        }
    }
    
    public FileModel getValueAt(int rowIndex) {
        return _fileList.get(rowIndex);
    }

    /**
     * @return the showHidden
     */
    public boolean getIfIsHidden() {
        return _showHidden;
    }

    /**
     * @param showHidden the showHidden to set
     */
    public void setShowHidden(boolean showHidden) {
        this._showHidden = showHidden;
    }
}
